<!--{template /module/admin/view/head}-->
<style type="text/css">
    #div_tag_list .btn {text-shadow:none; background:#fff; border:1px solid #ccc; border-radius:0;}
    #div_tag_list .btn:focus {outline:none;}
    #div_tag_list .btn-inverse {color:#00af4f; text-shadow:none; background:#fff; border:1px solid #00af4f;}
</style>
<div id="left_layout">
    <div id="main_content" class="container-fluid" style="padding-top:0;">
        <!--{template /module/admin/view/head_nav}-->
        <div class="row-fluid">
            <div class="well widget" style="border-top:0; padding-top:5px;">
                <div class="widget-content">
                    <form id="frm_grid" name="frmGrid" action="{$ADMIN_SCRIPT}/admin/file/_ilinei&frame=content&file={$_var[gp_file]}&path={$_var[gp_path]}" method="post">
                        <input type="hidden" name="formsubmit" value="yes" />
                        <fieldset>
                            <span class="help-inline">
                                快捷键：CTL+D匹配；CTL+/注释；CTL+K删除；CTL+L选择行，支持tab缩进！
                            </span>
                            <textarea name="txtContent" id="txt_content" style="width:98%; background:#f3f3f3; color:#008200;" rows="16" cols="80">{$file[content]}</textarea>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!--{template /module/admin/view/ilinei_frame_tag}-->

<script type="text/javascript" src="static/plugins/emmet.js"></script>

<script>
    var tag_maker = new Array();

    //空TAG
    tag_maker['blank'] = function(){
        var block = '';

        block += '<' + '!--{';
        block += 'block file=""';
        block += '/}-->';
        block += "\r\n";

        return block;
    }

    tag_maker['block'] = function(){
        var block = '';

        block += '<' + '!--{';
        block += 'block file="' + $("#tag-block input[name='rdoBlock']:checked").val() + '"';
        block += '/}-->';
        block += "\r\n";

        return block;
    }

    tag_maker['cms_model__category_multi'] = function(){
        var block = '';

        var var_name = $("#tag-cms_model__category_multi input[name='txtVar']").val();
        if(!var_name) var_name = 'categories';

        block += '<' + '!--{';
        block += 'block model="\\cms\\model\\_category" method="multi"';
        block += ' identity="' + $("#tag-cms_model__category_multi input[name='txtIdentity']").val() + '"';
        block += ' var="' + var_name + '"';
        block += '}-->';
        block += "\r\n";

        var tmpHTML = $('#tpl-cms_model__category_multi').val();
        tmpHTML = tmpHTML.replace('{VAR}', var_name);
        tmpHTML = tmpHTML.replace('{LINK}', $("#tag-cms_model__category_multi select[name='sltLink']").val());
        block += tmpHTML;

        block += "\r\n";
        block += '<' + '!--{';
        block += '/' + 'block';
        block += '}-->';
        block += "\r\n";

        return block;
    }

    tag_maker['cms_model__category_crumbs'] = function(){
        var block = '';

        var var_name = $("#tag-cms_model__category_crumbs input[name='txtVar']").val();
        if(!var_name) var_name = 'crumbs';

        block += '<' + '!--{';
        block += 'block model="\\cms\\model\\_category" method="crumbs"';
        block += ' identity="' + $("#tag-cms_model__category_crumbs input[name='txtIdentity']").val() + '"';
        block += ' var="' + var_name + '"';
        block += '}-->';
        block += "\r\n";

        var tmpHTML = $('#tpl-cms_model__category_crumbs').val();
        tmpHTML = tmpHTML.replace('{VAR}', var_name);
        tmpHTML = tmpHTML.replace('{LINK}', $("#tag-cms_model__category_crumbs select[name='sltLink']").val());
        block += tmpHTML;

        block += "\r\n";
        block += '<' + '!--{';
        block += '/' + 'block';
        block += '}-->';
        block += "\r\n";

        return block;
    }

    tag_maker['cms_model__category_one'] = function(){
        var block = '';

        var var_name = $("#tag-cms_model__category_one input[name='txtVar']").val();
        if(!var_name) var_name = 'category';

        block += '<' + '!--{';
        block += 'block model="\\cms\\model\\_category" method="one"';
        block += ' param="' + $("#tag-cms_model__category_one input[name='txtParam']").val() + '"';

        if($("#tag-cms_model__category_one input[name='txtType']").val()){
            block += ' type="' + $("#tag-cms_model__category_one input[name='txtType']").val() + '"';
        }

        block += ' var="' + var_name + '"';
        block += '}-->';
        block += "\r\n";

        var tmpHTML = $('#tpl-cms_model__category_one').val();
        tmpHTML = tmpHTML.replace('{VAR}', var_name);
        tmpHTML = tmpHTML.replace('{LINK}', $("#tag-cms_model__category_one select[name='sltLink']").val());
        block += tmpHTML;

        block += "\r\n";
        block += '<' + '!--{';
        block += '/' + 'block';
        block += '}-->';
        block += "\r\n";

        return block;
    }

    tag_maker['cms_model__article_multi'] = function(){
        var block = '';

        var var_name = $("#tag-cms_model__article_multi input[name='txtVar']").val();
        if(!var_name) var_name = 'articles';

        block += '<' + '!--{';
        block += 'block model="\\cms\\model\\_article" method="multi"';
        block += ' identity="' + $("#tag-cms_model__article_multi input[name='txtIdentity']").val() + '"';
        block += ' limit="' + $("#tag-cms_model__article_multi input[name='txtLimit']").val() + '"';

        if($("#tag-cms_model__article_multi input[name='txtParam']").val()){
            block += ' param="' + $("#tag-cms_model__article_multi input[name='txtParam']").val() + '"';
        }

        if($("#tag-cms_model__article_multi input[name='cbxPager']:checked").length > 0){
            block += ' pager="true"';
        }

        block += ' var="' + var_name + '"';
        block += '}-->';
        block += "\r\n";

        var tmpHTML = $('#tpl-cms_model__article_multi').val();
        tmpHTML = tmpHTML.replace('{VAR}', var_name);
        tmpHTML = tmpHTML.replace('{LINK}', $("#tag-cms_model__article_multi select[name='sltLink']").val());
        tmpHTML = $(tmpHTML);

        var columns = new Array();
        $("#tag-cms_model__article_multi input[name='cbxColumn']:checked").each(function(index, item){
            columns[item.value] = true;
        });

        if(columns['image']) $(tmpHTML).find('.row-text').remove();
        else $(tmpHTML).find('.row-image').remove();

        if(!columns['subtitle']) $(tmpHTML).find('.subtitle').remove();
        if(!columns['pubdate']) $(tmpHTML).find('.pubdate').remove();
        if(!columns['hits']) $(tmpHTML).find('.hits').remove();
        if(!columns['down']) $(tmpHTML).find('.down').remove();
        if(!columns['writer']) $(tmpHTML).find('.writer').remove();
        if(!columns['address']) $(tmpHTML).find('.address').remove();
        if(!columns['keywords']) $(tmpHTML).find('.keywords').remove();
        if(!columns['summary']) $(tmpHTML).find('.summary').remove();
        if(!columns['share']) $(tmpHTML).find('.baidu-share').remove();

        block += $(tmpHTML).prop("outerHTML");

        block += "\r\n";
        block += '<' + '!--{';
        block += '/' + 'block';
        block += '}-->';
        block += "\r\n";

        return block;
    }

    tag_maker['cms_model__article_one'] = function(){
        var block = '';

        var var_name = $("#tag-cms_model__article_one input[name='txtVar']").val();
        if(!var_name) var_name = 'article';

        block += '<' + '!--{';
        block += 'block model="\\cms\\model\\_article" method="one"';
        block += ' param="' + $("#tag-cms_model__article_one input[name='txtParam']").val() + '"';
        block += ' var="' + var_name + '"';
        block += '}-->';
        block += "\r\n";

        var tmpHTML = $("#tpl-cms_model__article_one").val();
        tmpHTML = tmpHTML.replace('{VAR}', var_name);
        tmpHTML = tmpHTML.replace('{LINK}', $("#tag-cms_model__article_one select[name='sltLink']").val());
        tmpHTML = $(tmpHTML);

        var columns = new Array();
        $("#tag-cms_model__article_one input[name='cbxColumn']:checked").each(function(index, item){
            columns[item.value] = true;
        });

        if(!columns['subtitle']) $(tmpHTML).find('.subtitle').remove();
        if(!columns['pubdate']) $(tmpHTML).find('.pubdate').remove();
        if(!columns['hits']) $(tmpHTML).find('.hits').remove();
        if(!columns['down']) $(tmpHTML).find('.down').remove();
        if(!(columns['pubdate'] || columns['hits'] || columns['down'])) $(tmpHTML).find('.pub-hit-down').remove();
        if(!columns['writer']) $(tmpHTML).find('.writer').remove();
        if(!columns['address']) $(tmpHTML).find('.address').remove();
        if(!(columns['writer'] || columns['address'])) $(tmpHTML).find('.wri-add').remove();
        if(!columns['keywords']) $(tmpHTML).find('.keywords').remove();
        if(!columns['summary']) $(tmpHTML).find('.summary').remove();
        if(!columns['share']) $(tmpHTML).find('.baidu-share').remove();
        if(!columns['other']) $(tmpHTML).find('.prev-next').remove();

        block += $(tmpHTML).prop("outerHTML");

        block += "\r\n";
        block += '<' + '!--{';
        block += '/' + 'block';
        block += '}-->';
        block += "\r\n";

        return block;
    }

    tag_maker['ad_model__adlog'] = function(){
        var block = '';

        block += '<' + '!--{';
        block += 'adlog ' + $("#tag-ad_model__adlog input[name='txtIdentity']").val();
        block += '/}-->';
        block += "\r\n";

        return block;
    }

    $(function(){
        $('.fancy').uniform();
        $('#txt_content').css('height', ($(document).height() - 100) + 'px');

        emmet.require('textarea').setup({
            pretty_break:true,
            use_tab:true
        });
    });

    function save(){
        $.dialog({submit:'{lang admin.ilinei.frame_parser.view.submit}', message:'<p>{lang admin.ilinei.frame_parser.view.submit.message}</p>', callback:function(){
            $('#modal_dialog .btn-primary').click(function(){
                $('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/admin/file/_ilinei&frame=content&file={$_var[gp_file]}&path={$_var[gp_path]}');
                $('#frm_grid').submit();
            });
        }});
    }

    function block_add(){
        $.dialog({title:'{lang admin.ilinei.frame_parser.view.block.title}', width:700, submit:'{lang admin.ilinei.frame_parser.view.block.add}', message:$('#txt_tag_list').val(), callback:function(){
            $('#modal_dialog .fancy').uniform();

            $('#modal_dialog .-ilinei-tag .tag-blank').hide();
            $('#modal_dialog .-ilinei-tag .tag-block').addClass('btn-inverse');
            $('#tag-block').show();

            $('#modal_dialog .-ilinei-tag .btn').click(function(){
                $('#modal_dialog .-ilinei-tag .btn').removeClass('btn-inverse');
                $(this).addClass('btn-inverse');

                $('#div_tag_list .tag').hide();
                $('#tag-' + $(this).attr('rel')).show();
            });

            $('#modal_dialog .btn-primary').click(function(){
                //检查是否选了。
                var rel = $('#div_tag_list .btn-inverse').attr('rel');
                if(!rel) return;

                if($('#tag-' + rel).length == 0 || !tag_maker[rel]) return;

                var code = tag_maker[rel]();
                var content = $('#txt_content').get(0);

                content.value = content.value.substr(0, content.selectionStart) + code + content.value.substring(content.selectionStart, content.value.length);

                $('#modal_dialog').modal('hide').remove();
            });
        }});
    }
</script>

<!--{template /module/admin/view/foot}-->